<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    on-ok="handleOk"
    switch-fullscreen
    :ok-button-props="{ props: { disabled: disableSubmit } }"
    cancel-text="关闭"
    @ok="handleOk"
    @cancel="handleCancel"
  >
        <template slot="footer">
          <a-button key="back" @click="handleCancel">
            关闭
          </a-button>
        </template>
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="7" :sm="8">
            <a-form-item label="标题" :label-col="{span: 6}" :wrapper-col="{span: 14, offset: 1}">
              <a-input v-model="queryParam.title" placeholder="请输入标题"/>
            </a-form-item>
          </a-col>
          <a-col :md="7" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" style="margin-left: 8px" @click="searchReset">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table
      ref="table"
      row-key="id"
      size="middle"
      :columns="columns"
      :data-source="dataSource"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      bordered
      class="j-table-force-nowrap"
    >
      <template slot="logo" slot-scope="text">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
        <img
          v-else
          :src="text"
          height="25px"
          alt=""
          style="max-width:80px;font-size: 12px;font-style: italic;"
        >
      </template>
      <span slot="action" slot-scope="text, record">
        <a @click="handleAdd(record)">
          设为轮播图
        </a>
      </span>
    </a-table>
  </a-modal>
</template>

<script>

import {TableListMixin} from '@/mixins/TableListMixin'
import {postAction} from "@/api/manage";

export default {
  name: 'AntsWxSwiperModal',
  components: {
  },

  mixins: [TableListMixin],
  data() {
    return {
      title: '',
      width: 1000,
      visible: false,
      disableSubmit: false,

      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 120,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '作者',
          align: 'center',
          dataIndex: 'realname'
        },
        {
          title: '标题',
          align: 'center',
          dataIndex: 'title',
        },
        {
          title: '标题',
          align: 'center',
          dataIndex: 'cover',
          scopedSlots: {customRender: 'logo'}
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: '10%',
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: '/antsWxSwiper/selectArticle',
        add: '/antsWxSwiper/add'
      }
    }
  },
  methods: {
    add() {
      this.visible = true
      this.loadData()
    },
    handleOk(e) {
      this.$emit('ok')
    },
    handleCancel(e) {
      this.visible = false
      this.$emit('ok')
    },
    // 设为轮播图
    handleAdd(record) {
      postAction(this.url.add,{
        articleId: record.id
      }).then(res => {
        if (res.success) {
          this.loadData()
          this.$message.success("操作成功！")
        }
      })
    }
  }
}
</script>
